package com.dragon.backstage.domain.param.menu;

import com.dragon.common.utils.AjaxResult;
import com.dragon.interfaces.constant.MenuConstant;
import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Objects;

/**
 * 菜单模块-更改菜单状态请求参数
 *
 * @author dragon
 * @version 1.0
 * @date 2024/8/6 18:21
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(title = "菜单模块-更改菜单状态请求参数")
public class MenuChangeStatusParam {

    /**
     * 菜单ID
     */
    @Schema(title = "菜单ID", requiredMode = Schema.RequiredMode.REQUIRED)
    private Long menuId;

    /**
     * 菜单状态（1显示 0隐藏）
     */
    @Builder.Default
    @Schema(title = "菜单状态（1显示 0隐藏）", requiredMode = Schema.RequiredMode.REQUIRED)
    private Byte status = 1;


    /**
     * 参数校验
     *
     * @param param 参数
     * @return AjaxResult<Void>
     */
    public static AjaxResult<Void> check(MenuChangeStatusParam param) {
        // 菜单状态枚举值
        List<Byte> statusArr = Lists.newArrayList(
            MenuConstant.STATUS_NORMAL,
            MenuConstant.STATUS_DISABLED
        );

        if (Objects.isNull(param)) {
            return AjaxResult.failed("请求参数不能为空");
        }

        if (Objects.isNull(param.getMenuId()) || param.getMenuId().equals(0L)) {
            return AjaxResult.failed("菜单ID不能为空");
        }

        if (Objects.isNull(param.getStatus())) {
            return AjaxResult.failed("菜单状态不能为空");
        }
        if (!statusArr.contains(param.getStatus())) {
            return AjaxResult.failed("菜单状态的值不符");
        }

        return AjaxResult.succeed();
    }

}
